home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.09 Sep 96 / Getting Started / AppletFrame.java next >
Encoding:
Java Source  |  1996-08-14  |  845 b   |  55 lines  |  [TEXT/CWIE]

  1. package com.metrowerks;
  2.  
  3. import java.awt.*;
  4. import java.applet.Applet;
  5.  
  6. public class AppletFrame extends Frame
  7. {
  8.     public static void startApplet( String className,
  9.                     String title, String args[])
  10.     {
  11.         Applet a;
  12.         Dimension appletSize;
  13.  
  14.         try {
  15.             a = (Applet)
  16.                     Class.forName(className).newInstance();
  17.         } catch (ClassNotFoundException e) {
  18.             return;
  19.         } catch (InstantiationException e) {
  20.             return;
  21.         } catch (IllegalAccessException e) {
  22.             return;
  23.         }
  24.  
  25.         a.init();
  26.         a.start();
  27.     
  28.         AppletFrame f = new AppletFrame(title);
  29.     
  30.         f.add("Center", a);
  31.     
  32.         appletSize =  a.size();
  33.         f.pack();
  34.         f.resize(appletSize);
  35.         f.show();
  36.     
  37.     }
  38.  
  39.     public AppletFrame(String name)
  40.     {
  41.         super(name);
  42.     }
  43.  
  44.     public boolean handleEvent(Event e)
  45.     {
  46.         if (e.id == Event.WINDOW_DESTROY)
  47.         {
  48.             dispose();
  49.             return true;
  50.         }
  51.         
  52.         return super.handleEvent(e);
  53.     }
  54. }
  55.